In [2]:
!pip install librosa
Collecting librosa
  Downloading librosa-0.10.2.post1-py3-none-any.whl.metadata (8.6 kB)
Collecting audioread>=2.1.9 (from librosa)
  Downloading audioread-3.0.1-py3-none-any.whl.metadata (8.4 kB)
Requirement already satisfied: numpy!=1.22.0,!=1.22.1,!=1.22.2,>=1.20.3 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from librosa) (1.26.4)
Requirement already satisfied: scipy>=1.2.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from librosa) (1.13.1)
Requirement already satisfied: scikit-learn>=0.20.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from librosa) (1.5.0)
Requirement already satisfied: joblib>=0.14 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from librosa) (1.4.2)
Requirement already satisfied: decorator>=4.3.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from librosa) (5.1.1)
Collecting numba>=0.51.0 (from librosa)
  Downloading numba-0.60.0-cp312-cp312-win_amd64.whl.metadata (2.8 kB)
Collecting soundfile>=0.12.1 (from librosa)
  Downloading soundfile-0.12.1-py2.py3-none-win_amd64.whl.metadata (14 kB)
Collecting pooch>=1.1 (from librosa)
  Downloading pooch-1.8.2-py3-none-any.whl.metadata (10 kB)
Collecting soxr>=0.3.2 (from librosa)
  Downloading soxr-0.3.7-cp312-cp312-win_amd64.whl.metadata (5.7 kB)
Requirement already satisfied: typing-extensions>=4.1.1 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from librosa) (4.12.2)
Collecting lazy-loader>=0.1 (from librosa)
  Downloading lazy_loader-0.4-py3-none-any.whl.metadata (7.6 kB)
Collecting msgpack>=1.0 (from librosa)
  Downloading msgpack-1.0.8-cp312-cp312-win_amd64.whl.metadata (9.4 kB)
Requirement already satisfied: packaging in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from lazy-loader>=0.1->librosa) (24.1)
Collecting llvmlite<0.44,>=0.43.0dev0 (from numba>=0.51.0->librosa)
  Downloading llvmlite-0.43.0-cp312-cp312-win_amd64.whl.metadata (4.9 kB)
Requirement already satisfied: platformdirs>=2.5.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from pooch>=1.1->librosa) (4.2.2)
Requirement already satisfied: requests>=2.19.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from pooch>=1.1->librosa) (2.32.3)
Requirement already satisfied: threadpoolctl>=3.1.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from scikit-learn>=0.20.0->librosa) (3.5.0)
Requirement already satisfied: cffi>=1.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from soundfile>=0.12.1->librosa) (1.16.0)
Requirement already satisfied: pycparser in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from cffi>=1.0->soundfile>=0.12.1->librosa) (2.22)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (2.2.2)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (2024.6.2)
Downloading librosa-0.10.2.post1-py3-none-any.whl (260 kB)
   ---------------------------------------- 0.0/260.1 kB ? eta -:--:--
   ---- ----------------------------------- 30.7/260.1 kB 1.3 MB/s eta 0:00:01
   --------- ----------------------------- 61.4/260.1 kB 812.7 kB/s eta 0:00:01
   -------------------------- ------------- 174.1/260.1 kB 1.5 MB/s eta 0:00:01
   ---------------------------------------  256.0/260.1 kB 1.6 MB/s eta 0:00:01
   ---------------------------------------- 260.1/260.1 kB 1.3 MB/s eta 0:00:00
Downloading audioread-3.0.1-py3-none-any.whl (23 kB)
Downloading lazy_loader-0.4-py3-none-any.whl (12 kB)
Downloading msgpack-1.0.8-cp312-cp312-win_amd64.whl (75 kB)
   ---------------------------------------- 0.0/75.3 kB ? eta -:--:--
   ---------------------------------------- 75.3/75.3 kB 4.1 MB/s eta 0:00:00
Downloading numba-0.60.0-cp312-cp312-win_amd64.whl (2.7 MB)
   ---------------------------------------- 0.0/2.7 MB ? eta -:--:--
   --- ------------------------------------ 0.3/2.7 MB 7.7 MB/s eta 0:00:01
   ------ --------------------------------- 0.4/2.7 MB 5.1 MB/s eta 0:00:01
   -------- ------------------------------- 0.6/2.7 MB 4.6 MB/s eta 0:00:01
   ------------ --------------------------- 0.8/2.7 MB 4.7 MB/s eta 0:00:01
   ------------- -------------------------- 0.9/2.7 MB 4.0 MB/s eta 0:00:01
   ---------------- ----------------------- 1.1/2.7 MB 4.1 MB/s eta 0:00:01
   ---------------------- ----------------- 1.5/2.7 MB 4.7 MB/s eta 0:00:01
   ----------------------- ---------------- 1.6/2.7 MB 5.0 MB/s eta 0:00:01
   ------------------------ --------------- 1.7/2.7 MB 3.9 MB/s eta 0:00:01
   ------------------------- -------------- 1.7/2.7 MB 3.6 MB/s eta 0:00:01
   ------------------------------- -------- 2.1/2.7 MB 4.2 MB/s eta 0:00:01
   ------------------------------- -------- 2.1/2.7 MB 4.2 MB/s eta 0:00:01
   ----------------------------------- ---- 2.4/2.7 MB 4.0 MB/s eta 0:00:01
   ---------------------------------------  2.7/2.7 MB 4.2 MB/s eta 0:00:01
   ---------------------------------------- 2.7/2.7 MB 4.1 MB/s eta 0:00:00
Downloading pooch-1.8.2-py3-none-any.whl (64 kB)
   ---------------------------------------- 0.0/64.6 kB ? eta -:--:--
   ---------------------------------------- 64.6/64.6 kB 3.4 MB/s eta 0:00:00
Downloading soundfile-0.12.1-py2.py3-none-win_amd64.whl (1.0 MB)
   ---------------------------------------- 0.0/1.0 MB ? eta -:--:--
   ----------------- ---------------------- 0.4/1.0 MB 9.2 MB/s eta 0:00:01
   ------------------------ --------------- 0.6/1.0 MB 7.7 MB/s eta 0:00:01
   ------------------------------- -------- 0.8/1.0 MB 5.6 MB/s eta 0:00:01
   ---------------------------------------  1.0/1.0 MB 5.7 MB/s eta 0:00:01
   ---------------------------------------- 1.0/1.0 MB 5.3 MB/s eta 0:00:00
Downloading soxr-0.3.7-cp312-cp312-win_amd64.whl (184 kB)
   ---------------------------------------- 0.0/184.1 kB ? eta -:--:--
   --------------------------------------- 184.1/184.1 kB 10.9 MB/s eta 0:00:00
Downloading llvmlite-0.43.0-cp312-cp312-win_amd64.whl (28.1 MB)
   ---------------------------------------- 0.0/28.1 MB ? eta -:--:--
    --------------------------------------- 0.5/28.1 MB 10.5 MB/s eta 0:00:03
    --------------------------------------- 0.7/28.1 MB 7.3 MB/s eta 0:00:04
   - -------------------------------------- 0.9/28.1 MB 7.0 MB/s eta 0:00:04
   - -------------------------------------- 1.0/28.1 MB 5.5 MB/s eta 0:00:05
   - -------------------------------------- 1.2/28.1 MB 5.6 MB/s eta 0:00:05
   - -------------------------------------- 1.4/28.1 MB 5.2 MB/s eta 0:00:06
   -- ------------------------------------- 1.6/28.1 MB 4.7 MB/s eta 0:00:06
   -- ------------------------------------- 1.7/28.1 MB 4.6 MB/s eta 0:00:06
   -- ------------------------------------- 1.9/28.1 MB 4.5 MB/s eta 0:00:06
   --- ------------------------------------ 2.1/28.1 MB 4.5 MB/s eta 0:00:06
   --- ------------------------------------ 2.3/28.1 MB 4.4 MB/s eta 0:00:06
   --- ------------------------------------ 2.5/28.1 MB 4.4 MB/s eta 0:00:06
   --- ------------------------------------ 2.7/28.1 MB 4.3 MB/s eta 0:00:06
   ---- ----------------------------------- 2.8/28.1 MB 4.3 MB/s eta 0:00:06
   ---- ----------------------------------- 2.8/28.1 MB 4.1 MB/s eta 0:00:07
   ---- ----------------------------------- 3.1/28.1 MB 4.1 MB/s eta 0:00:07
   ---- ----------------------------------- 3.3/28.1 MB 4.0 MB/s eta 0:00:07
   ---- ----------------------------------- 3.4/28.1 MB 4.0 MB/s eta 0:00:07
   ---- ----------------------------------- 3.4/28.1 MB 4.0 MB/s eta 0:00:07
   ----- ---------------------------------- 3.5/28.1 MB 3.7 MB/s eta 0:00:07
   ----- ---------------------------------- 3.8/28.1 MB 3.8 MB/s eta 0:00:07
   ----- ---------------------------------- 4.0/28.1 MB 3.8 MB/s eta 0:00:07
   ----- ---------------------------------- 4.1/28.1 MB 3.8 MB/s eta 0:00:07
   ------ --------------------------------- 4.3/28.1 MB 3.8 MB/s eta 0:00:07
   ------ --------------------------------- 4.5/28.1 MB 3.8 MB/s eta 0:00:07
   ------ --------------------------------- 4.8/28.1 MB 3.7 MB/s eta 0:00:07
   ------ --------------------------------- 4.9/28.1 MB 3.8 MB/s eta 0:00:07
   ------- -------------------------------- 5.1/28.1 MB 3.8 MB/s eta 0:00:07
   ------- -------------------------------- 5.3/28.1 MB 3.8 MB/s eta 0:00:07
   ------- -------------------------------- 5.5/28.1 MB 3.8 MB/s eta 0:00:07
   -------- ------------------------------- 5.6/28.1 MB 3.7 MB/s eta 0:00:06
   -------- ------------------------------- 5.8/28.1 MB 3.7 MB/s eta 0:00:07
   -------- ------------------------------- 6.0/28.1 MB 3.8 MB/s eta 0:00:06
   -------- ------------------------------- 6.2/28.1 MB 3.7 MB/s eta 0:00:06
   --------- ------------------------------ 6.3/28.1 MB 3.8 MB/s eta 0:00:06
   --------- ------------------------------ 6.5/28.1 MB 3.7 MB/s eta 0:00:06
   --------- ------------------------------ 6.7/28.1 MB 3.7 MB/s eta 0:00:06
   --------- ------------------------------ 6.9/28.1 MB 3.7 MB/s eta 0:00:06
   ---------- ----------------------------- 7.0/28.1 MB 3.7 MB/s eta 0:00:06
   ---------- ----------------------------- 7.2/28.1 MB 3.7 MB/s eta 0:00:06
   ---------- ----------------------------- 7.4/28.1 MB 3.7 MB/s eta 0:00:06
   ---------- ----------------------------- 7.5/28.1 MB 3.7 MB/s eta 0:00:06
   ---------- ----------------------------- 7.7/28.1 MB 3.7 MB/s eta 0:00:06
   ----------- ---------------------------- 7.9/28.1 MB 3.7 MB/s eta 0:00:06
   ----------- ---------------------------- 8.1/28.1 MB 3.7 MB/s eta 0:00:06
   ----------- ---------------------------- 8.2/28.1 MB 3.7 MB/s eta 0:00:06
   ----------- ---------------------------- 8.2/28.1 MB 3.6 MB/s eta 0:00:06
   ----------- ---------------------------- 8.4/28.1 MB 3.7 MB/s eta 0:00:06
   ------------ --------------------------- 8.6/28.1 MB 3.6 MB/s eta 0:00:06
   ------------ --------------------------- 8.7/28.1 MB 3.6 MB/s eta 0:00:06
   ------------ --------------------------- 8.9/28.1 MB 3.6 MB/s eta 0:00:06
   ------------ --------------------------- 9.1/28.1 MB 3.6 MB/s eta 0:00:06
   ------------- -------------------------- 9.2/28.1 MB 3.6 MB/s eta 0:00:06
   ------------- -------------------------- 9.4/28.1 MB 3.6 MB/s eta 0:00:06
   ------------- -------------------------- 9.5/28.1 MB 3.6 MB/s eta 0:00:06
   ------------- -------------------------- 9.7/28.1 MB 3.6 MB/s eta 0:00:06
   -------------- ------------------------- 9.9/28.1 MB 3.6 MB/s eta 0:00:06
   -------------- ------------------------- 10.1/28.1 MB 3.6 MB/s eta 0:00:05
   -------------- ------------------------- 10.2/28.1 MB 3.6 MB/s eta 0:00:05
   -------------- ------------------------- 10.3/28.1 MB 3.6 MB/s eta 0:00:05
   -------------- ------------------------- 10.5/28.1 MB 3.5 MB/s eta 0:00:05
   --------------- ------------------------ 10.7/28.1 MB 3.5 MB/s eta 0:00:06
   --------------- ------------------------ 10.9/28.1 MB 3.5 MB/s eta 0:00:05
   --------------- ------------------------ 11.0/28.1 MB 3.5 MB/s eta 0:00:05
   --------------- ------------------------ 11.1/28.1 MB 3.4 MB/s eta 0:00:05
   ---------------- ----------------------- 11.3/28.1 MB 3.4 MB/s eta 0:00:05
   ---------------- ----------------------- 11.5/28.1 MB 3.4 MB/s eta 0:00:05
   ---------------- ----------------------- 11.7/28.1 MB 3.4 MB/s eta 0:00:05
   ---------------- ----------------------- 11.8/28.1 MB 3.4 MB/s eta 0:00:05
   ----------------- ---------------------- 12.0/28.1 MB 3.4 MB/s eta 0:00:05
   ----------------- ---------------------- 12.2/28.1 MB 3.4 MB/s eta 0:00:05
   ----------------- ---------------------- 12.4/28.1 MB 3.4 MB/s eta 0:00:05
   ----------------- ---------------------- 12.5/28.1 MB 3.4 MB/s eta 0:00:05
   ------------------ --------------------- 12.7/28.1 MB 3.4 MB/s eta 0:00:05
   ------------------ --------------------- 12.9/28.1 MB 3.4 MB/s eta 0:00:05
   ------------------ --------------------- 13.1/28.1 MB 3.4 MB/s eta 0:00:05
   ------------------ --------------------- 13.3/28.1 MB 3.5 MB/s eta 0:00:05
   ------------------- -------------------- 13.4/28.1 MB 3.5 MB/s eta 0:00:05
   ------------------- -------------------- 13.6/28.1 MB 3.6 MB/s eta 0:00:05
   ------------------- -------------------- 13.8/28.1 MB 3.6 MB/s eta 0:00:05
   ------------------- -------------------- 13.9/28.1 MB 3.5 MB/s eta 0:00:05
   -------------------- ------------------- 14.1/28.1 MB 3.5 MB/s eta 0:00:04
   -------------------- ------------------- 14.3/28.1 MB 3.5 MB/s eta 0:00:04
   -------------------- ------------------- 14.5/28.1 MB 3.5 MB/s eta 0:00:04
   -------------------- ------------------- 14.6/28.1 MB 3.5 MB/s eta 0:00:04
   --------------------- ------------------ 14.8/28.1 MB 3.5 MB/s eta 0:00:04
   --------------------- ------------------ 14.8/28.1 MB 3.5 MB/s eta 0:00:04
   --------------------- ------------------ 15.0/28.1 MB 3.5 MB/s eta 0:00:04
   --------------------- ------------------ 15.2/28.1 MB 3.5 MB/s eta 0:00:04
   --------------------- ------------------ 15.4/28.1 MB 3.5 MB/s eta 0:00:04
   ---------------------- ----------------- 15.6/28.1 MB 3.5 MB/s eta 0:00:04
   ---------------------- ----------------- 15.7/28.1 MB 3.5 MB/s eta 0:00:04
   ---------------------- ----------------- 15.9/28.1 MB 3.5 MB/s eta 0:00:04
   ---------------------- ----------------- 16.1/28.1 MB 3.5 MB/s eta 0:00:04
   ----------------------- ---------------- 16.3/28.1 MB 3.5 MB/s eta 0:00:04
   ----------------------- ---------------- 16.4/28.1 MB 3.5 MB/s eta 0:00:04
   ----------------------- ---------------- 16.6/28.1 MB 3.5 MB/s eta 0:00:04
   ----------------------- ---------------- 16.8/28.1 MB 3.5 MB/s eta 0:00:04
   ------------------------ --------------- 17.0/28.1 MB 3.5 MB/s eta 0:00:04
   ------------------------ --------------- 17.1/28.1 MB 3.5 MB/s eta 0:00:04
   ------------------------ --------------- 17.3/28.1 MB 3.5 MB/s eta 0:00:04
   ------------------------ --------------- 17.5/28.1 MB 3.5 MB/s eta 0:00:04
   ------------------------- -------------- 17.6/28.1 MB 3.5 MB/s eta 0:00:04
   ------------------------- -------------- 17.8/28.1 MB 3.5 MB/s eta 0:00:03
   ------------------------- -------------- 18.0/28.1 MB 3.5 MB/s eta 0:00:03
   ------------------------- -------------- 18.2/28.1 MB 3.5 MB/s eta 0:00:03
   -------------------------- ------------- 18.4/28.1 MB 3.5 MB/s eta 0:00:03
   -------------------------- ------------- 18.5/28.1 MB 3.5 MB/s eta 0:00:03
   -------------------------- ------------- 18.6/28.1 MB 3.5 MB/s eta 0:00:03
   -------------------------- ------------- 18.6/28.1 MB 3.5 MB/s eta 0:00:03
   -------------------------- ------------- 18.6/28.1 MB 3.5 MB/s eta 0:00:03
   -------------------------- ------------- 18.6/28.1 MB 3.5 MB/s eta 0:00:03
   -------------------------- ------------- 18.6/28.1 MB 3.3 MB/s eta 0:00:03
   -------------------------- ------------- 18.9/28.1 MB 3.3 MB/s eta 0:00:03
   -------------------------- ------------- 18.9/28.1 MB 3.3 MB/s eta 0:00:03
   -------------------------- ------------- 18.9/28.1 MB 3.3 MB/s eta 0:00:03
   -------------------------- ------------- 18.9/28.1 MB 3.3 MB/s eta 0:00:03
   -------------------------- ------------- 18.9/28.1 MB 3.3 MB/s eta 0:00:03
   --------------------------- ------------ 19.1/28.1 MB 3.1 MB/s eta 0:00:03
   ---------------------------- ----------- 20.2/28.1 MB 3.4 MB/s eta 0:00:03
   ---------------------------- ----------- 20.4/28.1 MB 3.4 MB/s eta 0:00:03
   ----------------------------- ---------- 20.6/28.1 MB 3.4 MB/s eta 0:00:03
   ----------------------------- ---------- 20.7/28.1 MB 3.4 MB/s eta 0:00:03
   ----------------------------- ---------- 21.0/28.1 MB 3.5 MB/s eta 0:00:03
   ------------------------------ --------- 21.1/28.1 MB 3.4 MB/s eta 0:00:03
   ------------------------------ --------- 21.3/28.1 MB 3.5 MB/s eta 0:00:02
   ------------------------------ --------- 21.5/28.1 MB 3.4 MB/s eta 0:00:02
   ------------------------------ --------- 21.7/28.1 MB 3.5 MB/s eta 0:00:02
   ------------------------------- -------- 21.8/28.1 MB 3.5 MB/s eta 0:00:02
   ------------------------------- -------- 22.0/28.1 MB 3.5 MB/s eta 0:00:02
   ------------------------------- -------- 22.2/28.1 MB 3.5 MB/s eta 0:00:02
   ------------------------------- -------- 22.4/28.1 MB 3.5 MB/s eta 0:00:02
   -------------------------------- ------- 22.5/28.1 MB 3.5 MB/s eta 0:00:02
   -------------------------------- ------- 22.7/28.1 MB 3.5 MB/s eta 0:00:02
   -------------------------------- ------- 22.7/28.1 MB 3.5 MB/s eta 0:00:02
   -------------------------------- ------- 22.7/28.1 MB 3.5 MB/s eta 0:00:02
   -------------------------------- ------- 22.7/28.1 MB 3.5 MB/s eta 0:00:02
   -------------------------------- ------- 22.7/28.1 MB 3.5 MB/s eta 0:00:02
   -------------------------------- ------- 22.7/28.1 MB 3.5 MB/s eta 0:00:02
   -------------------------------- ------- 22.7/28.1 MB 3.5 MB/s eta 0:00:02
   ---------------------------------- ----- 24.0/28.1 MB 3.5 MB/s eta 0:00:02
   ---------------------------------- ----- 24.1/28.1 MB 3.5 MB/s eta 0:00:02
   ---------------------------------- ----- 24.3/28.1 MB 3.5 MB/s eta 0:00:02
   ---------------------------------- ----- 24.5/28.1 MB 3.5 MB/s eta 0:00:02
   ----------------------------------- ---- 24.7/28.1 MB 3.5 MB/s eta 0:00:01
   ----------------------------------- ---- 24.8/28.1 MB 3.5 MB/s eta 0:00:01
   ----------------------------------- ---- 25.0/28.1 MB 3.5 MB/s eta 0:00:01
   ----------------------------------- ---- 25.2/28.1 MB 3.5 MB/s eta 0:00:01
   ------------------------------------ --- 25.4/28.1 MB 3.5 MB/s eta 0:00:01
   ------------------------------------ --- 25.5/28.1 MB 3.5 MB/s eta 0:00:01
   ------------------------------------ --- 25.7/28.1 MB 3.5 MB/s eta 0:00:01
   ------------------------------------ --- 25.9/28.1 MB 3.5 MB/s eta 0:00:01
   ------------------------------------- -- 26.1/28.1 MB 3.5 MB/s eta 0:00:01
   ------------------------------------- -- 26.2/28.1 MB 3.5 MB/s eta 0:00:01
   ------------------------------------- -- 26.4/28.1 MB 3.5 MB/s eta 0:00:01
   ------------------------------------- -- 26.6/28.1 MB 3.5 MB/s eta 0:00:01
   -------------------------------------- - 26.7/28.1 MB 3.5 MB/s eta 0:00:01
   -------------------------------------- - 26.9/28.1 MB 3.5 MB/s eta 0:00:01
   -------------------------------------- - 27.1/28.1 MB 3.5 MB/s eta 0:00:01
   -------------------------------------- - 27.3/28.1 MB 3.5 MB/s eta 0:00:01
   ---------------------------------------  27.4/28.1 MB 3.5 MB/s eta 0:00:01
   ---------------------------------------  27.6/28.1 MB 3.5 MB/s eta 0:00:01
   ---------------------------------------  27.8/28.1 MB 3.5 MB/s eta 0:00:01
   ---------------------------------------  27.9/28.1 MB 3.5 MB/s eta 0:00:01
   ---------------------------------------  28.1/28.1 MB 3.5 MB/s eta 0:00:01
   ---------------------------------------  28.1/28.1 MB 3.5 MB/s eta 0:00:01
   ---------------------------------------- 28.1/28.1 MB 3.4 MB/s eta 0:00:00
Installing collected packages: soxr, msgpack, llvmlite, lazy-loader, audioread, soundfile, pooch, numba, librosa
Successfully installed audioread-3.0.1 lazy-loader-0.4 librosa-0.10.2.post1 llvmlite-0.43.0 msgpack-1.0.8 numba-0.60.0 pooch-1.8.2 soundfile-0.12.1 soxr-0.3.7
In [4]:
!pip install seaborn
Collecting seaborn
  Downloading seaborn-0.13.2-py3-none-any.whl.metadata (5.4 kB)
Requirement already satisfied: numpy!=1.24.0,>=1.20 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from seaborn) (1.26.4)
Requirement already satisfied: pandas>=1.2 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from seaborn) (2.2.2)
Requirement already satisfied: matplotlib!=3.6.1,>=3.4 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from seaborn) (3.9.0)
Requirement already satisfied: contourpy>=1.0.1 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (1.2.1)
Requirement already satisfied: cycler>=0.10 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (4.53.0)
Requirement already satisfied: kiwisolver>=1.3.1 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (1.4.5)
Requirement already satisfied: packaging>=20.0 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (24.1)
Requirement already satisfied: pillow>=8 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (10.3.0)
Requirement already satisfied: pyparsing>=2.3.1 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (3.1.2)
Requirement already satisfied: python-dateutil>=2.7 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from pandas>=1.2->seaborn) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from pandas>=1.2->seaborn) (2024.1)
Requirement already satisfied: six>=1.5 in c:\users\mahip\appdata\local\programs\python\python312\lib\site-packages (from python-dateutil>=2.7->matplotlib!=3.6.1,>=3.4->seaborn) (1.16.0)
Downloading seaborn-0.13.2-py3-none-any.whl (294 kB)
   ---------------------------------------- 0.0/294.9 kB ? eta -:--:--
   ----- --------------------------------- 41.0/294.9 kB 960.0 kB/s eta 0:00:01
   ----- --------------------------------- 41.0/294.9 kB 960.0 kB/s eta 0:00:01
   ------ -------------------------------- 51.2/294.9 kB 327.7 kB/s eta 0:00:01
   --------- ----------------------------- 71.7/294.9 kB 357.2 kB/s eta 0:00:01
   --------- ----------------------------- 71.7/294.9 kB 357.2 kB/s eta 0:00:01
   ------------ -------------------------- 92.2/294.9 kB 327.7 kB/s eta 0:00:01
   --------------- ---------------------- 122.9/294.9 kB 359.9 kB/s eta 0:00:01
   ------------------ ------------------- 143.4/294.9 kB 387.0 kB/s eta 0:00:01
   ---------------------- --------------- 174.1/294.9 kB 402.6 kB/s eta 0:00:01
   ------------------------- ------------ 194.6/294.9 kB 406.9 kB/s eta 0:00:01
   ------------------------------- ------ 245.8/294.9 kB 471.0 kB/s eta 0:00:01
   ----------------------------------- -- 276.5/294.9 kB 486.7 kB/s eta 0:00:01
   ------------------------------------ - 286.7/294.9 kB 453.2 kB/s eta 0:00:01
   -------------------------------------- 294.9/294.9 kB 455.5 kB/s eta 0:00:00
Installing collected packages: seaborn
Successfully installed seaborn-0.13.2
In [53]:
import os
import librosa
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
from tensorflow.keras.layers import Input, Conv2D, MaxPool2D, Flatten, Dense,Dropout
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.utils import to_categorical
from tensorflow.image import resize
import seaborn as sns
In [6]:
example_file="Data/genres_original/blues/blues.00000.wav" #Copy path
In [7]:
# sr-Sampling Rate
# y,sr=librosa.load(example_file) #Takes default sr
x,sr=librosa.load(example_file,sr=44100)

x.shape
# sr
Out[7]:
(1323588,)
In [8]:
plt.figure(figsize=(14,5))
librosa.display.waveshow(x, sr=sr)
Out[8]:
<librosa.display.AdaptiveWaveplot at 0x1a275b45b80>
No description has been provided for this image
In [9]:
from IPython.display import Audio
Audio(data=x,rate=sr)
Out[9]:
Your browser does not support the audio element.
In [10]:
audio_path = "./blues.0000.wav"
y,sr= librosa.load(example_file,sr=None) #sr=None-- keep original sampling Rate
chunk_duration = 4
overlap_duration = 2

#Calculate y for Chunk -- convert duration to Sample
chunk_samples = chunk_duration * sr
overlap_samples = overlap_duration * sr

# Calculate no of chunks
no_of_chunks= int(np.ceil((len(y)-chunk_samples)/(chunk_samples- overlap_samples)))+1

# Iteration of each chunk
for i in range(no_of_chunks):
  start= i* (chunk_samples - overlap_samples) # 0-4, 2-6,
  end = start + chunk_samples
  chunk= y[start:end]
  plt.figure(figsize=(4,2))
  librosa.display.waveshow(chunk,sr=sr)
  plt.show()
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [12]:
#Plotting Melspectrogram of Entire audio
def plot_melspectrogram(y,sr):
    # Compute the spectrogram
    spectrogram = librosa.feature.melspectrogram(y=y, sr=sr)
    # Convert to decibels (log scale)
    spectrogram_db = librosa.power_to_db(spectrogram, ref=np.max)
    # Visualize the spectrogram
    plt.figure(figsize=(10, 4))
    librosa.display.specshow(spectrogram_db, sr=sr, x_axis='time', y_axis='mel')
    plt.colorbar(format='%+2.0f dB')
    plt.title('Spectrogram')
    plt.tight_layout()
    plt.show()
In [13]:
def plot_melspectrogram_chunks(y,sr):
    # Define the duration of each chunk and overlap
    chunk_duration = 4  # seconds
    overlap_duration = 2  # seconds

    # Convert durations to samples
    chunk_samples = chunk_duration * sr
    overlap_samples = overlap_duration * sr

    # Calculate the number of chunks
    num_chunks = int(np.ceil((len(y) - chunk_samples) / (chunk_samples - overlap_samples))) + 1

    # Iterate over each chunk
    for i in range(num_chunks):
        # Calculate start and end indices of the chunk
        start = i * (chunk_samples - overlap_samples)
        end = start + chunk_samples

        # Extract the chunk of audio
        chunk = y[start:end]

        # Compute the Mel spectrogram for the chunk
        mel_spectrogram = librosa.feature.melspectrogram(y=chunk, sr=sr)
        print(mel_spectrogram.shape)
        spectrogram_db = librosa.power_to_db(mel_spectrogram, ref=np.max)
        # Visualize the spectrogram
        plt.figure(figsize=(10, 4))
        librosa.display.specshow(spectrogram_db, sr=sr, x_axis='time', y_axis='mel')
        plt.colorbar(format='%+2.0f dB')
        plt.title('Spectrogram')
        plt.tight_layout()
        plt.show()

#Spectrogram of Audio chunks
plot_melspectrogram_chunks(y=x,sr=sr)
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 173)
No description has been provided for this image
(128, 88)
No description has been provided for this image
In [17]:
# Define your folder structure
data_dir = 'Data/genres_original'
classes = ['blues', 'classical','country','disco','hiphop','metal','pop','reggae','rock']
In [19]:
# Load and preprocess audio data
def load_and_preprocess_data(data_dir, classes, target_shape=(150, 150)):
    data = []
    labels = []

    for i_class, class_name in enumerate(classes):
        class_dir = os.path.join(data_dir, class_name)
        print("Processing--",class_name)
        for filename in os.listdir(class_dir):
            if filename.endswith('.wav'):
                file_path = os.path.join(class_dir, filename)
                audio_data, sample_rate = librosa.load(file_path, sr=None)
                # Perform preprocessing (e.g., convert to Mel spectrogram and resize)
                # Define the duration of each chunk and overlap
                chunk_duration = 4  # seconds
                overlap_duration = 2  # seconds

                # Convert durations to samples
                chunk_samples = chunk_duration * sample_rate
                overlap_samples = overlap_duration * sample_rate

                # Calculate the number of chunks
                num_chunks = int(np.ceil((len(audio_data) - chunk_samples) / (chunk_samples - overlap_samples))) + 1

                # Iterate over each chunk
                for i in range(num_chunks):
                    # Calculate start and end indices of the chunk
                    start = i * (chunk_samples - overlap_samples)
                    end = start + chunk_samples

                    # Extract the chunk of audio
                    chunk = audio_data[start:end]

                    # Compute the Mel spectrogram for the chunk
                    mel_spectrogram = librosa.feature.melspectrogram(y=chunk, sr=sr)

                #mel_spectrogram = librosa.feature.melspectrogram(y=audio_data, sr=sample_rate)
                    mel_spectrogram = resize(np.expand_dims(mel_spectrogram, axis=-1), target_shape)
                    data.append(mel_spectrogram)
                    labels.append(i_class)

    return np.array(data), np.array(labels)
In [21]:
# Split data into training and testing sets
data, labels = load_and_preprocess_data(data_dir, classes)
#print("\nData:",data,"\nlabel",labels)
Processing-- blues
Processing-- classical
Processing-- country
Processing-- disco
Processing-- hiphop
Processing-- metal
Processing-- pop
Processing-- reggae
Processing-- rock
In [34]:
data.shape
Out[34]:
(13490, 150, 150, 1)
In [23]:
labels.shape
Out[23]:
(13490,)
In [24]:
labels
Out[24]:
array([0, 0, 0, ..., 8, 8, 8])
In [25]:
labels = to_categorical(labels, num_classes=len(classes))  # Convert labels to one-hot encoding
labels
Out[25]:
array([[1., 0., 0., ..., 0., 0., 0.],
       [1., 0., 0., ..., 0., 0., 0.],
       [1., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 1.],
       [0., 0., 0., ..., 0., 0., 1.],
       [0., 0., 0., ..., 0., 0., 1.]])
In [26]:
labels.shape
Out[26]:
(13490, 9)
In [27]:
data.shape
Out[27]:
(13490, 150, 150, 1)
In [28]:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.2, random_state=42)
In [49]:
#model = tf.keras.models.Sequential()
X_train[0].shape
Out[49]:
(150, 150, 1)
In [57]:
input_shape=(150, 150, 1)
model = tf.keras.models.Sequential()
model.add(Conv2D(filters=32,kernel_size=3,padding='same',activation='relu',input_shape=X_train[0].shape))
model.add(Conv2D(filters=32,kernel_size=3,activation='relu'))
model.add(MaxPool2D(pool_size=2,strides=2))
model.add(Conv2D(filters=64,kernel_size=3,padding='same',activation='relu'))
model.add(Conv2D(filters=64,kernel_size=3,activation='relu'))
model.add(MaxPool2D(pool_size=2,strides=2))
model.add(Conv2D(filters=128,kernel_size=3,padding='same',activation='relu'))
model.add(Conv2D(filters=128,kernel_size=3,activation='relu'))
model.add(MaxPool2D(pool_size=2,strides=2))
model.add(tf.keras.layers.Dropout(0.3))
model.add(Conv2D(filters=256,kernel_size=3,padding='same',activation='relu'))
model.add(Conv2D(filters=256,kernel_size=3,activation='relu'))
model.add(MaxPool2D(pool_size=2,strides=2))
model.add(Conv2D(filters=512,kernel_size=3,padding='same',activation='relu'))
model.add(Conv2D(filters=512,kernel_size=3,activation='relu'))
model.add(MaxPool2D(pool_size=2,strides=2))
model.add(Dropout(0.3))
model.add(Flatten())
model.add(Dense(units=1200,activation='relu'))
model.add(Dropout(0.45))
model.add(Dense(units=len(classes),activation='softmax'))
model.summary()
Model: "sequential_8"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type)                         ┃ Output Shape                ┃         Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ conv2d_68 (Conv2D)                   │ (None, 150, 150, 32)        │             320 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_69 (Conv2D)                   │ (None, 148, 148, 32)        │           9,248 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ max_pooling2d_30 (MaxPooling2D)      │ (None, 74, 74, 32)          │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_70 (Conv2D)                   │ (None, 74, 74, 64)          │          18,496 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_71 (Conv2D)                   │ (None, 72, 72, 64)          │          36,928 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ max_pooling2d_31 (MaxPooling2D)      │ (None, 36, 36, 64)          │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_72 (Conv2D)                   │ (None, 36, 36, 128)         │          73,856 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_73 (Conv2D)                   │ (None, 34, 34, 128)         │         147,584 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ max_pooling2d_32 (MaxPooling2D)      │ (None, 17, 17, 128)         │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dropout_13 (Dropout)                 │ (None, 17, 17, 128)         │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_74 (Conv2D)                   │ (None, 17, 17, 256)         │         295,168 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_75 (Conv2D)                   │ (None, 15, 15, 256)         │         590,080 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ max_pooling2d_33 (MaxPooling2D)      │ (None, 7, 7, 256)           │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_76 (Conv2D)                   │ (None, 7, 7, 512)           │       1,180,160 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv2d_77 (Conv2D)                   │ (None, 5, 5, 512)           │       2,359,808 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ max_pooling2d_34 (MaxPooling2D)      │ (None, 2, 2, 512)           │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dropout_14 (Dropout)                 │ (None, 2, 2, 512)           │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ flatten_4 (Flatten)                  │ (None, 2048)                │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense_8 (Dense)                      │ (None, 1200)                │       2,458,800 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dropout_15 (Dropout)                 │ (None, 1200)                │               0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense_9 (Dense)                      │ (None, 9)                   │          10,809 │
└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
 Total params: 7,181,257 (27.39 MB)
 Trainable params: 7,181,257 (27.39 MB)
 Non-trainable params: 0 (0.00 B)
In [58]:
model.compile(optimizer=Adam(learning_rate=0.0001), loss='categorical_crossentropy', metrics=['accuracy'])
X_train.shape,y_train.shape
Out[58]:
((10792, 150, 150, 1), (10792, 9))
In [60]:
training_history = model.fit(X_train, y_train, epochs=10, batch_size=32, validation_data=(X_test, y_test))
Epoch 1/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 2442s 7s/step - accuracy: 0.2252 - loss: 2.0303 - val_accuracy: 0.4211 - val_loss: 1.5778
Epoch 2/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 2148s 6s/step - accuracy: 0.4819 - loss: 1.4469 - val_accuracy: 0.6012 - val_loss: 1.1371
Epoch 3/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 1147s 3s/step - accuracy: 0.6074 - loss: 1.1256 - val_accuracy: 0.6312 - val_loss: 1.0535
Epoch 4/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 1745s 5s/step - accuracy: 0.6839 - loss: 0.9168 - val_accuracy: 0.7368 - val_loss: 0.7908
Epoch 5/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 2172s 6s/step - accuracy: 0.7253 - loss: 0.8005 - val_accuracy: 0.7113 - val_loss: 0.8585
Epoch 6/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 2219s 6s/step - accuracy: 0.7706 - loss: 0.6711 - val_accuracy: 0.7880 - val_loss: 0.6331
Epoch 7/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 6799s 20s/step - accuracy: 0.7933 - loss: 0.5973 - val_accuracy: 0.7891 - val_loss: 0.6064
Epoch 8/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 657s 2s/step - accuracy: 0.8316 - loss: 0.5035 - val_accuracy: 0.8002 - val_loss: 0.5793
Epoch 9/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 684s 2s/step - accuracy: 0.8558 - loss: 0.4282 - val_accuracy: 0.8202 - val_loss: 0.5166
Epoch 10/10
338/338 ━━━━━━━━━━━━━━━━━━━━ 745s 2s/step - accuracy: 0.8688 - loss: 0.3784 - val_accuracy: 0.8462 - val_loss: 0.4464
In [61]:
model.save("Trained_model.h5") #Windows
WARNING:absl:You are saving your model as an HDF5 file via `model.save()` or `keras.saving.save_model(model)`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')` or `keras.saving.save_model(model, 'my_model.keras')`. 
In [62]:
model.save("Trained_model.keras") #Windows
In [ ]: